package com.example.a02back.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author : JCccc
 * @CreateTime : 2019/10/8
 * @Description :
 **/

@Controller
public class WebSocketController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * @Description: 
     * @Author: SimpChaos 
     * @Date: 2022/7/21 7:19
     * @Param: [name, model]
     * @Return: java.lang.String
     */
    @RequestMapping("/websocket/{name}")
    public String webSocket(@PathVariable String name, Model model) {
        try {
            logger.info("跳转到websocket的页面上");
            System.out.println(name);
            model.addAttribute("username", name);
            return "websocket";
        } catch (Exception e) {
            logger.info("跳转到websocket的页面上发生异常，异常信息是：" + e.getMessage());
            return "error";
        }
    }

    /**
     * @Description: 
     * @Author: SimpChaos 
     * @Date: 2022/7/21 7:19
     * @Param: [name, model]
     * @Return: java.lang.String
     */
    @RequestMapping("/websocketS/{name}")
    public String websocketS(@PathVariable String name, Model model) {
        try {
            logger.info("跳转到websocket的页面上");
            System.out.println(name);
            model.addAttribute("username", name);
            return "websocketS";
        } catch (Exception e) {
            logger.info("跳转到websocket的页面上发生异常，异常信息是：" + e.getMessage());
            return "error";
        }
    }

    /**
     * @Description: 
     * @Author: SimpChaos 
     * @Date: 2022/7/21 8:13
     * @Param: []
     * @Return: java.lang.String
     */
    @RequestMapping("/testPage")
    public String testPage() {

        return "testPage";

    }
}